import { Router, Request, Response } from 'express';
import { handleStripeWebhook } from '../controllers/webhook.controller';

const router = Router();

/**
 * POST /api/webhooks/stripe
 * Handle Stripe webhook events
 * Note: This route must use raw body parser (configured in index.ts)
 */
router.post('/', async (req: Request, res: Response) => {
  try {
    await handleStripeWebhook(req, res);
  } catch (error) {
    console.error('Error in webhook route:', error);
    res.status(500).json({ error: 'Webhook handler failed' });
  }
});

export default router;
